﻿#ifndef PST_THREEDCLOUDMAPSIDEBARDATA_H
#define PST_THREEDCLOUDMAPSIDEBARDATA_H

#include <QObject>
#include <QDomNodeList>
#include <QDomElement>
#include <QDomText>
#include <QDomAttr>
#include "TextFileParser.h"
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    class ThreeDCloudMapSidebarData :public QObject
    {
        Q_OBJECT

    public:
        ThreeDCloudMapSidebarData(QObject* parent = nullptr) :QObject(parent) {}
        ~ThreeDCloudMapSidebarData() {}

        void setGraphName(const QString& graphName) { m_graphName = graphName; }
        QString getGraphName() const { return m_graphName; }

        void setIsGraphNameRenamed(bool isRenamed) { m_isGraphNameRenamed = isRenamed; };
        bool getIsGraphNameRenamed() { return m_isGraphNameRenamed; };

        void setTextFileParser(TextFileParser* textFileParser) { m_textFileParser = textFileParser; }
        TextFileParser* getTextFileParser() const { return m_textFileParser; }

        void setIsShowActor(bool isShowActor) { m_isShowActor = isShowActor; }
        bool getIsShowActor() const { return m_isShowActor; }

        int getCurrentShowType() const { return m_currentShowType; }
        void setCurrentShowType(int currentShowType) { m_currentShowType = currentShowType; }

        int getCurrentFixedParamIndex() const { return m_currentFixedParamIndex; }
        void setCurrentFixedParamIndex(int currentFixedParamIndex) { m_currentFixedParamIndex = currentFixedParamIndex; }

        QList<QString> getValueGroupNameList() const { return m_valueGroupNameList; }
        void setValueGroupNameList(const QList<QString>& valueList) { m_valueGroupNameList = valueList; }

        int getCurrentValueGroupNameIndex() const { return m_currentValueGroupNameIndex; }
        void setCurrentValueGroupNameIndex(int currentValueIndex) { m_currentValueGroupNameIndex = currentValueIndex; }

        void setCurrentComponentIndex(int index) { m_currentComponentIndex = index; }
        int getCurrentComponentIndex() const { return m_currentComponentIndex; }

        bool getIsLog() const { return m_isLog; }
        void setIsLog(bool isLog) { m_isLog = isLog; }

        bool getIsNormalized() const { return m_isNormalized; }
        void setIsNormalized(bool isNormalized) { m_isNormalized = isNormalized; }

        void setXSliceEnum(const QList<double>& xSliceEnum) { m_xSliceEnum = xSliceEnum; }
        QList<double> getXSliceEnum() const { return m_xSliceEnum; }

        void setYSliceEnum(const QList<double>& ySliceEnum) { m_ySliceEnum = ySliceEnum; }
        QList<double> getYSliceEnum() const { return m_ySliceEnum; }

        void setZSliceEnum(const QList<double>& zSliceEnum) { m_zSliceEnum = zSliceEnum; }
        QList<double> getZSliceEnum() const { return m_zSliceEnum; }

        void setXSliceUnit(const QString& xSliceUnit) { xSlicePositionUnit = xSliceUnit; }
        QString getXSliceUnit() const { return xSlicePositionUnit; }

        void setYSliceUnit(const QString& ySliceUnit) { ySlicePositionUnit = ySliceUnit; }
        QString getYSliceUnit() const { return ySlicePositionUnit; }

        void setZSliceUnit(const QString& zSliceUnit) { zSlicePositionUnit = zSliceUnit; }
        QString getZSliceUnit() const { return zSlicePositionUnit; }

        void setDataSource(const QString& dataSource) { m_dataSource = dataSource; };
        QString getDataSource() const { return m_dataSource; };

        void PrintSelf() const
        {
            qInfo() << "m_graphName:" << m_graphName;
            qInfo() << "m_isShowActor:" << m_isShowActor;
            qInfo() << "m_isShowActor:" << m_isShowActor;
            qInfo() << "m_currentShowType:" << m_currentShowType;
            qInfo() << "m_currentFixedParamIndex:" << m_currentFixedParamIndex;
            qInfo() << "m_currentComponentIndex:" << m_currentComponentIndex;
            qInfo() << "m_valueGroupNameList:" << m_valueGroupNameList;
            qInfo() << "m_currentValueGroupNameIndex:" << m_currentValueGroupNameIndex;
            qInfo() << "m_isLog:" << m_isLog;
            qInfo() << "m_xSliceEnum:" << m_xSliceEnum;
            qInfo() << "m_ySliceEnum:" << m_ySliceEnum;
            qInfo() << "m_zSliceEnum:" << m_zSliceEnum;
            qInfo() << "xSlicePositionUnit:" << xSlicePositionUnit;
            qInfo() << "ySlicePositionUnit:" << ySlicePositionUnit;
            qInfo() << "zSlicePositionUnit:" << zSlicePositionUnit;
            qInfo() << "m_dataSource:" << m_dataSource;
        }

        /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false)
        {
            QDomElement _ThreeDCloudMapSidebarDataRoot = doc->createElement("ThreeDCloudMapSidebarData");

            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "GraphName", m_graphName);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "IsGraphNameRenamed", QString::number(m_isGraphNameRenamed));
            m_textFileParser->writeToProjectFile(doc, &_ThreeDCloudMapSidebarDataRoot, isdiso);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "IsShowActor", QString::number(m_isShowActor));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "CurrentShowType", QString::number(m_currentShowType));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "CurrentFixedParamIndex", QString::number(m_currentFixedParamIndex));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "ValueGroupNameList", m_valueGroupNameList.join(';'));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "CurrentValueGroupNameIndex", QString::number(m_currentValueGroupNameIndex));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "CurrentComponentIndex", QString::number(m_currentComponentIndex));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "IsLog", QString::number(m_isLog));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "IsNormalized", QString::number(m_isNormalized));
            auto _xSliceEnumStr = GlobalHelperInstance->convertDoubleListToQString(m_xSliceEnum);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "XSliceEnum", _xSliceEnumStr);
            auto _ySliceEnumStr = GlobalHelperInstance->convertDoubleListToQString(m_ySliceEnum);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "YSliceEnum", _ySliceEnumStr);
            auto _zSliceEnumStr = GlobalHelperInstance->convertDoubleListToQString(m_zSliceEnum);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "ZSliceEnum", _zSliceEnumStr);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "XSlicePositionUnit", xSlicePositionUnit);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "YSlicePositionUnit", ySlicePositionUnit);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "ZSlicePositionUnit", zSlicePositionUnit);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDCloudMapSidebarDataRoot, "DataSource", m_dataSource);

            element->appendChild(_ThreeDCloudMapSidebarDataRoot);

            return _ThreeDCloudMapSidebarDataRoot;
        }
        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false)
        {
            auto _GraphNameNodeList = element->elementsByTagName("GraphName");
            m_graphName = _GraphNameNodeList.item(0).toElement().text();
            auto _IsGraphNameRenamedNodeList = element->elementsByTagName("IsGraphNameRenamed");
            m_isGraphNameRenamed = (bool)_IsGraphNameRenamedNodeList.item(0).toElement().text().toInt();
            m_textFileParser->readFromProjectFile(&element->elementsByTagName("TextFileParser"), isdiso);
            auto _IsShowActorNodeList = element->elementsByTagName("IsShowActor");
            m_isShowActor = (bool)_IsShowActorNodeList.item(0).toElement().text().toInt();
            auto _CurrentShowTypeNodeList = element->elementsByTagName("CurrentShowType");
            m_currentShowType = (int)_CurrentShowTypeNodeList.item(0).toElement().text().toInt();
            auto _CurrentFixedParamIndexNodeList = element->elementsByTagName("CurrentFixedParamIndex");
            m_currentFixedParamIndex = (int)_CurrentFixedParamIndexNodeList.item(0).toElement().text().toInt();
            auto _ValueGroupNameListNodeList = element->elementsByTagName("ValueGroupNameList");
            m_valueGroupNameList = _ValueGroupNameListNodeList.item(0).toElement().text().split(';');
            auto _CurrentValueGroupNameIndexNodeList = element->elementsByTagName("CurrentValueGroupNameIndex");
            m_currentValueGroupNameIndex = (int)_CurrentValueGroupNameIndexNodeList.item(0).toElement().text().toInt();
            auto _CurrentComponentIndexNodeList = element->elementsByTagName("CurrentComponentIndex");
            m_currentComponentIndex = (int)_CurrentComponentIndexNodeList.item(0).toElement().text().toInt();
            auto _IsLogNodeList = element->elementsByTagName("IsLog");
            m_isLog = (bool)_IsLogNodeList.item(0).toElement().text().toInt();
            auto _IsNormalizedNodeList = element->elementsByTagName("IsNormalized");
            m_isNormalized = (bool)_IsNormalizedNodeList.item(0).toElement().text().toInt();
            auto _XSliceEnumNodeList = element->elementsByTagName("XSliceEnum");
            m_xSliceEnum = GlobalHelperInstance->convertStringToDoubleList(_XSliceEnumNodeList.item(0).toElement().text());
            auto _YSliceEnumNodeList = element->elementsByTagName("YSliceEnum");
            m_ySliceEnum = GlobalHelperInstance->convertStringToDoubleList(_YSliceEnumNodeList.item(0).toElement().text());
            auto _ZSliceEnumNodeList = element->elementsByTagName("ZSliceEnum");
            m_zSliceEnum = GlobalHelperInstance->convertStringToDoubleList(_ZSliceEnumNodeList.item(0).toElement().text());
            auto _XSlicePositionUnitNodeList = element->elementsByTagName("XSlicePositionUnit");
            xSlicePositionUnit = _XSlicePositionUnitNodeList.item(0).toElement().text();
            auto _YSlicePositionUnitNodeList = element->elementsByTagName("YSlicePositionUnit");
            ySlicePositionUnit = _YSlicePositionUnitNodeList.item(0).toElement().text();
            auto _ZSlicePositionUnitNodeList = element->elementsByTagName("ZSlicePositionUnit");
            zSlicePositionUnit = _ZSlicePositionUnitNodeList.item(0).toElement().text();
            auto _DataSourceNodeList = element->elementsByTagName("DataSource");
            m_dataSource = _DataSourceNodeList.item(0).toElement().text();
        }

    private:
        QString m_graphName = ""; //图名称
        bool m_isGraphNameRenamed = false;//是否有被手动重命名过
        TextFileParser* m_textFileParser = nullptr;
        bool m_isShowActor = true;
        //0123分别为表面，xoy, yoz, zox
        int m_currentShowType = 0;
        int m_currentFixedParamIndex = 0;
        QList<QString> m_valueGroupNameList;
        int m_currentValueGroupNameIndex = 0;
        int m_currentComponentIndex = 0;
        bool m_isLog = false;
        bool m_isNormalized = false;
        QList<double> m_xSliceEnum{};//x切面的枚举值
        QList<double> m_ySliceEnum{};//y切面的枚举值
        QList<double> m_zSliceEnum{};//z切面的枚举值
        QString xSlicePositionUnit{};
        QString ySlicePositionUnit{};
        QString zSlicePositionUnit{};
        QString m_dataSource = "";
    };
}
#endif
